package section_13.adapter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class ReversibleArrayList<T> extends ArrayList<T> {

	public ReversibleArrayList(Collection<? extends T> arg0) {
		super(arg0);
	}

	public Iterable<T> reversed() {
		return new Iterable<T>() {
			public Iterator<T> iterator() {
				return new Iterator<T>() {
					int current = size() - 1;

					public boolean hasNext() {
						return current > -1;
					}

					public T next() {
						return (T) get(current--);
					}

					public void remove() {
						throw new UnsupportedOperationException();
					}

				};
			}
		};
	}

}
